<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Navigator</title>
</head>

<body>
  <button onclick="share()">分享</button>
  <script>
    window.onload = () => {
      // webVR();
    }
    function webVR() {
      if (!navigator.getVRDisplays) {
        console.error("WebVR is not available");
      } else {
        console.log("WebVR is available");
        /* Use WebVR */
      }

    }
    function share() {
      // 分享
      if (navigator.share) {
        navigator.share({
          title: document.title,
          text: "Hello World",
          url: "https://developer.mozilla.org",
        }).then(() => {
          console.log('Share was successful');
        }).catch(error => {
          console.log('Sharing failed', error);
        });
      } else {
        // Fallback for older browsers or no support
        console.log('Sharing is not supported');
      }
    }
    function testNavigator() {
      let navigator = window.navigator;
      // 获取设备网络连接信息
      let connection = navigator.connection
      // console.log(connection);
      // 获取设备网络类型
      // console.log(connection.effectiveType);
      // 判断设备是否联网
      let onLine = navigator.onLine;
      // console.log(onLine);
      // 获取设备位置信息
      let geolocation = navigator.geolocation;
      // 获取设备当前位置
      geolocation.getCurrentPosition((position) => {
        console.log('当前位置', position);
      });
      // 获取当前浏览器的用户代理
      let userAgent = navigator.userAgent
      // 判断设备是否为PC端
      let isPC = /windows|macintosh|linux/i.test(userAgent);
      // console.log('是否为PC端', isPC);
      // 判断设备是否为移动端
      let isMobile = /iphone|ipod|android|mobile|blackberry|windows phone|opera mini|iemobile/i.test(userAgent);
      // console.log('是否为移动端', isMobile);
      // 判断设备是否为IOS设备还是安卓设备
      let isIOS = /iphone|ipod|ipad/i.test(userAgent);
      let isAndroid = /android/i.test(userAgent);
      // console.log('是否为IOS设备', isIOS);
      // console.log('是否为安卓设备', isAndroid);

    }
    // testNavigator();
  </script>
</body>

</html>